package com.nullpointer.xchatfinal.fragment;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;

import com.nullpointer.xchatfinal.R;

public class ChooseImageDialogFragment extends DialogFragment {
	private Button btGallery;
	private Button btCamera;
	private OnChooseImageDialogFragment listener;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_choose_image, container);
		findViewIds(view);
		init();
		setEvent();
		return view;
	}

	private void init() {
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
	}

	private void setEvent() {
		btGallery.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (listener != null) {
					listener.onGallery();
				}
				dismiss();
			}
		});

		btCamera.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				if (listener != null) {
					listener.onCamera();
				}
				dismiss();
			}
		});
	}

	private void findViewIds(View view) {
		btGallery = (Button) view.findViewById(R.id.bt_gallery);
		btCamera = (Button) view.findViewById(R.id.bt_camera);
	}

	public void setOnChooseImageDialogFragment(
			OnChooseImageDialogFragment listener) {
		this.listener = listener;
	}

	public interface OnChooseImageDialogFragment {
		void onGallery();

		void onCamera();
	}
}
